<?php

!defined('DEBUG') AND exit('Access Denied.');

$action = param(1);

if(!admin_authority_check()) header("Location:".url('index-login'));

if($action == 'channel') {

	//参数
	$type = param('type', 0);	// 搜索类型
	$keywords = trim(param('keywords', ''));	// 关键字
	$fdate = param('fdate', date('Y-m-d H:i:s', strtotime('today')));	// 开始时间
	$tdate = param('tdate', date('Y-m-d H:i:s', strtotime('today')+86399));	// 结束时间
	//条件
	$where = 'where o.status=1';
	//$where = 'where 1';
	$timed = ' and time>='.strtotime($fdate).' and time<='.strtotime($tdate);
	$where.= $timed;
	if($keywords!=''){
		switch($type){
			case 1://支付宝账号
				$where.= " and c.alipay_account like'%".$keywords."%'";
				break;
			case 2://姓名
				$where.= " and c.alipay_realname like'%".$keywords."%'";
				break;
			default://通道
				$where.= " and c.name like'%".$keywords."%'";
				break;
		}
	}
	//订单查询
	$orders=db_sql_find("SELECT c.name,c.alipay_account,c.alipay_realname,count(o.id) as nums,sum(o.coin_pay) as coin_pay_total,sum(o.coin_merchant) as coin_merchant_total,sum(o.coin_proxy) as coin_proxy_total,sum(o.coin_plat) as coin_plat_total FROM ".$db->tablepre."order o left join ".$db->tablepre."channel c on c.id=o.chid $where group by o.chid order by o.chid asc");
	//print_r($orders);exit;
	
	//提现查询
	//已审核
	$cashs_success=db_sql_find_one("SELECT count(id) as nums, sum(coin) as coin_total, sum(fee) as fee_total FROM ".$db->tablepre."order_cash where status='已审核' $timed");
	//print_r($cashs_success);exit;
	//初始化0
	$cashs_success['coin_total']=$cashs_success['coin_total']?$cashs_success['coin_total']:0;
	$cashs_success['fee_total']=$cashs_success['fee_total']?$cashs_success['fee_total']:0;
	//待审核
	$cashs_wait=db_sql_find_one("SELECT count(id) as nums, sum(coin) as coin_total, sum(fee) as fee_total FROM ".$db->tablepre."order_cash where status='待审核' $timed");
	//print_r($cashs_wait);exit;
	//初始化0
	$cashs_wait['coin_total']=$cashs_wait['coin_total']?$cashs_wait['coin_total']:0;
	$cashs_wait['fee_total']=$cashs_wait['fee_total']?$cashs_wait['fee_total']:0;
	
	$header['title'] = '报表管理 - '.$conf['sitename'];
	include _include(ADMIN_PATH.'view/htm/report_channel.htm');
}
?>